class UID_:

    @staticmethod
    def uuid():
        import datetime
        import random
        import uuid
        uid = str(uuid.uuid1())

        inttime = int(datetime.datetime.now().strftime('%Y%m%d%H%M%S%f'))
        uuid = ''.join(uid.split('-')) + str(random.randrange(0, inttime)).zfill(20)
        return uuid

    # 定义四舍五入函数
    @staticmethod
    def new_round(_float, _len):
        if str(format(_float, '.' + str(_len + 1) + 'f'))[-1] == '5':
            return format(round(float(str(_float)[:-1] + '6'), _len), '.' + str(_len) + 'f')
        else:
            return format(round(_float, _len), '.' + str(_len) + 'f')

    @staticmethod
    def createGongXuTableSql(user_id):
        create_table_sql = """
CREATE TABLE GONGXU_{0} (
	ID INT IDENTITY(1,1) PRIMARY KEY, /*ID*/
	BOM_NO VARCHAR(500) NULL, /*BOM代号*/
	ITM INT NULL, /*BOM代号*/
	ZC_ITM INT NULL, /*加工顺序*/
	ZC_NO_UP VARCHAR(500)  NULL, /*承上制程*/
	ZC_NO_DN VARCHAR(500) NULL, /*转下制程*/
	XH INT NULL, /*序号*/
	CPPH VARCHAR(500) NULL, /*成品品号*/
	PRD_NO VARCHAR(500) NOT NULL, /*部件品号*/
	BJMC VARCHAR(500) NULL, /*部件名称*/
	PF_NO VARCHAR(500) NOT NULL, /*版本号*/
	ZC_NO VARCHAR(500) NOT NULL, /*工序代号*/
	GXMC VARCHAR(500) NULL, /*工序名称*/
	HPGG TEXT NULL, /*货品规格*/
	YL NUMERIC(22, 8) NULL, /*用量*/
	CZCS INT  NULL, /*操作次数*/
	SCGS NUMERIC(22, 8)  NOT NULL, /*实测工时*/
	KFL VARCHAR(500) NOT NULL, /*宽放率*/
	TIME_USED VARCHAR(500) NOT NULL, /*标准工时*/
	XCN NUMERIC(22, 8) NULL, /*新产能*/
	UP NUMERIC(22, 8) NOT NULL, /*新单价*/
	JCN NUMERIC(22, 8) NULL, /*旧产能*/
	JDJ NUMERIC(22, 8) NULL, /*旧单价*/
	B_DD VARCHAR(500) NOT NULL, /*计件单价开始使用日期*/
	REM TEXT NULL /*计件单价备注（变更原因）*/
)
        """.format(user_id)

        table_name = """
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME='GONGXU_{0}'
        """.format(user_id)
        return table_name,create_table_sql
